$(function(){
  let laypage = layui.laypage;
    // 查询参数
    let q = {
      page: 1,
      limit: 10,
      cateid:9,
    };
  // 导航栏
function renderNav(){
  axios({
      method:'get',
      url:'http://192.168.13.83:8060/home/index/index',
      params:{},
      }).then(function(res){
      // console.log(res);
      const {data}=res.data
      // console.log(data);       

      // 右侧banner
      const rightBanner=data.sideBanner.map((item)=>{
          const {id,advimglink,advimgdesc,advimgsrc}=item
          return `
          <a href="${advimglink}" rel="nofollow" target="_blank" title="${advimgdesc}">
          <img class="g430" style="width:360px;height:133px;" src="http://192.168.13.83:8060/${advimgsrc}" alt="${advimgdesc}" >
          </a>
          `
      }).join('')
      $('.textwidget').html(rightBanner)

      // 热门标签
      const tag=data.allTag.map((item)=>{
          return `
          <li><a title="" href="">${item.tagname}</a></li>
          ` 
          }).join('')
          $('.widget_tags_inner').html(tag)

           // 友情链接
           const link=data.allLink.map((item) =>{
              const {id,title,url,des,img}=item
              return `
              <li>
              <a href="${url}"><img src="http://192.168.13.83:8060/${img}" alt=""><p>${des}</p></a>
          </li>
              `
              }).join('')
              $('.widget_comments ul').html(link)
  })
}
renderNav()

// 最新文章
function renderArt(){
  axios({
      method: 'GET',
      url: 'http://192.168.13.83:8060/home/index/recommend',
      }).then(function (res) {
      // console.log(res);
      const {data}=res.data
      // console.log(data.list);
      const strArt=data.list.map((item)=>{
        const {catename,id,pic,title,click}=item
          return `
          <li>
          <a target="_blank" href="javascript:;" data-id=${id} data-catename=${catename}>
            <span class="thumbnail">
              <img src="http://192.168.13.83:8060/${pic}" class="thumb" />
            </span>
            <span class="text">${title}</span>
            <span class="text-muted post-views">阅读(${click})</span>
          </a>
        </li>
          `
      }).join('')
      $('.items-02').html(strArt);
  })
  }
renderArt()

// 主体内容
function getRenderNew() {
  axios({
  method: 'GET',
  url: 'http://192.168.13.83:8060/home/index/new',
  params: q,
  }).then(function (res) {
  // console.log(res);
  let str = res.data.data.list.data
      .map(item => {
      return `
      <article class="excerpt excerpt-one">
      <header>
          <a class="cat label label-important" href="javascript:;">热门<i class="label-arrow"></i></a>
          <h2>
          <a href="javascript:;" class='skipList' id=${item.id} data-catename=${item.catename} title=${item.title}>${item.title}</a>
          </h2>
      </header>
      <p class="text-muted time">
          <a href="">悦享·编辑</a>发布于 ${time(item.create_date)}
      </p>
      <p class="focus">
          <a target="_blank" href="http://blog.weknow.cn/474.shtml" class="thumbnail">
          <span class="item"><span class="thumb-span"><img src="http://124.223.14.236:8060/${item.pic}"
                  class="thumb" /></span></span></a>
      </p>
      <p class="note">${item.description}</p>
      <p class="text-muted views">
          <span class="post-views">阅读(${item.click})</span>
          <span class="post-comments">评论(0)</span>
          <a href="javascript:;" >
          <i class="fa fa-thumbs-up"></i>赞 (<span id="lovenum">${item.lovenum}</span>)
          </a>
          <span class="post-tags">标签：
          <a href="" rel="tag">${item.keywords}</a> /
      </p>
      </article>
          `;
      })
      .join('');
  $('.recent').html(str);
  // 调用渲染分页的方法
  });
}
getRenderNew()

     // 时间函数
     function time(mesc) {
      let now = new Date(mesc);
      let year = getZero(now.getFullYear());
      let month = getZero(now.getMonth() + 1);
      let day = getZero(now.getDate());
      return year + '-' + month + '-' + day;
  }
  // 时间补零函数
  function getZero(num) {
      return num < 10 ? '0' + num : num;
  } 
})